Skip to content

Conversation

parkerbxyz
Copy link
Contributor

@parkerbxyz parkerbxyz commented Jun 13, 2024

Undici has added native support for proxy handling, so it is no longer necessary for us to implement our own custom proxy handling.
@parkerbxyz parkerbxyz self-assigned this Jun 13, 2024
@parkerbxyz parkerbxyz linked an issue Jun 13, 2024 that may be closed by this pull request
@gr2m gr2m force-pushed the 134-remove-custom-proxy-functionality branch from 47d08ea to 98eac26 Compare June 13, 2024 23:11
@parkerbxyz
Copy link
Contributor Author

parkerbxyz commented Jun 13, 2024

👋 @dmitrijrub @mikakesan Since you helped us test proxy functionality (#99) when we added support for it in #102, would you be willing to help us test this branch (134-remove-custom-proxy-functionality) to ensure you're still able to use this action with a proxy? 🙏

@gr2m gr2m self-assigned this Jun 14, 2024
@dmitrijrub
Copy link

hi @parkerbxyz, what are the changes? should I just use uses: actions/create-github-app-token@134-remove-custom-proxy-functionality ?

@parkerbxyz
Copy link
Contributor Author

parkerbxyz commented Jun 14, 2024

should I just use uses: actions/create-github-app-token@134-remove-custom-proxy-functionality ?

Yes, exactly! 🙂

@dmitrijrub
Copy link

dmitrijrub commented Jun 17, 2024

hmmm, looks like its failing

Run actions/create-github-app-token@134-remove-custom-proxy-functionality
owner and repositories not set, creating token for the current repository ("dt-arc")
Failed to create token for "dt-arc" (attempt 1): Connect Timeout Error
Failed to create token for "dt-arc" (attempt 2): Connect Timeout Error
Failed to create token for "dt-arc" (attempt 3): Connect Timeout Error
Failed to create token for "dt-arc" (attempt 4): Connect Timeout Error
RequestError [HttpError]: Connect Timeout Error
    at /home/runner/_work/_actions/actions/create-github-app-token/134-remove-custom-proxy-functionality/dist/main.cjs:3[7](https://github.com/company-company/dt-arc/actions/runs/9512488741/job/26317660736#step:10:8)097:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async hook4 (/home/runner/_work/_actions/actions/create-github-app-token/134-remove-custom-proxy-functionality/dist/main.cjs:39469:1[8](https://github.com/org-company/dt-arc/actions/runs/9512488741/job/26317660736#step:10:9))
    at async getTokenFromRepository (/home/runner/_work/_actions/actions/create-github-app-token/134-remove-custom-proxy-functionality/dist/main.cjs:3[9](https://github.com/telia-company/dt-arc/actions/runs/9512488741/job/26317660736#step:10:10)783:20)
    at async RetryOperation._fn (/home/runner/_work/_actions/actions/create-github-app-token/134-remove-custom-proxy-functionality/dist/main.cjs:39660:24) {
  status: 500,
  request: {
    method: 'GET',
    url: xxxx
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'actions/create-github-app-token',
      authorization: 'bearer [REDACTED]'
    },
    request: {
      fetch: [AsyncFunction: fetch],
      hook: [Function: bound hook4] AsyncFunction
    }
  },
  response: undefined,
  attemptNumber: 4,
  retriesLeft: 0
}
Error: Connect Timeout Error

@parkerbxyz
Copy link
Contributor Author

Noting this in case it is helpful later: nodejs/undici#1650 (comment)

@parkerbxyz parkerbxyz force-pushed the 134-remove-custom-proxy-functionality branch from bbbe985 to 1f00388 Compare September 4, 2024 00:18
@parkerbxyz
Copy link
Contributor Author

hmmm, looks like its failing

Thank you so much for testing that, @dmitrijrub! I've made some changes in hopes of fixing the failure you encountered. Would you mind testing again and letting us know how it goes, please? 🙏

@parkerbxyz
Copy link
Contributor Author

parkerbxyz commented Oct 4, 2024

Tests are currently failing due to our current use of the global dispatcher in our tests and local dispatcher in the fetch method. The problem can be reproduced with the following example:

import { EnvHttpProxyAgent, MockAgent, setGlobalDispatcher } from "undici";

const mockAgent = new MockAgent();
mockAgent.disableNetConnect();
setGlobalDispatcher(mockAgent);
const mockPool = mockAgent.get("https://example.test");

mockPool
  .intercept({
    path: `/`,
    method: "GET",
  })
  .reply(200);

await fetch("https://example.test", {
  // Comment out the following line to see the test succeed
  dispatcher: new EnvHttpProxyAgent(),
});

console.log("OK");

The global dispatcher is not being used when a local dispatcher is set. We need to verify if this is a feature or a bug.

@gr2m gr2m mentioned this pull request Oct 7, 2024
@parkerbxyz
Copy link
Contributor Author

The global dispatcher is not being used when a local dispatcher is set. We need to verify if this is a feature or a bug.

nodejs/undici#3792

@parkerbxyz
Copy link
Contributor Author

Deno appears to have native proxy support: https://docs.deno.com/runtime/reference/env_variables/#special-environment-variables

@gr2m
Copy link
Contributor

gr2m commented Nov 1, 2024

Deno appears to have native proxy support

I'm down for using Deno instead of Node.js, as long as we still generate the built files with all dependencies and execute that code instead of loading dependencies dynamically at run time.

@peter-evans
Copy link
Contributor

I just received a really helpful PR here: peter-evans/create-pull-request#3475

And that lead me to realise that proxy support can be simplified to this: peter-evans/create-pull-request#3483

It passes the proxy support tests I have, so looks good.

Just thought I would mention this in case it helps here.

@gr2m
Copy link
Contributor

gr2m commented Dec 19, 2024

Thank you @peter-evans! It looks like you use node-fetch-native as a dependency which depends on node-fetch, which is a huge dependency. We try to keep this action slim, so I'd like to avoid that.

We are interested in your test setup though and couldn't quite figure it out. Can you give us some pointers how you test the env-based proxy handling?

@peter-evans
Copy link
Contributor

It looks like you use node-fetch-native as a dependency which depends on node-fetch, which is a huge dependency. We try to keep this action slim, so I'd like to avoid that.

I see. Well I'm interested to see what solution you end up with here then.

We are interested in your test setup though and couldn't quite figure it out. Can you give us some pointers how you test the env-based proxy handling?

I created a small docker image to launch a forward proxy based on glider. In the test, I start the forward proxy and then configure the firewall on the actions runner. The firewall settings deny outgoing, except through the proxy. So it makes sure that the action is definitely using the proxy when it's configured.

@parkerbxyz parkerbxyz added this to the v2 milestone Mar 20, 2025
@parkerbxyz parkerbxyz removed this from the v2 milestone Apr 3, 2025
@parkerbxyz
Copy link
Contributor Author

It looks like Node.js v24 is going to include proxy support:

@parkerbxyz parkerbxyz changed the base branch from main to beta August 15, 2025 20:12
The undici package has been removed from the dependencies in package.json and package-lock.json, likely because it is no longer needed in the project.
@parkerbxyz parkerbxyz added this to the v3 milestone Aug 15, 2025
@parkerbxyz parkerbxyz marked this pull request as ready for review August 22, 2025 19:14
@parkerbxyz parkerbxyz requested a review from a team as a code owner August 22, 2025 19:14
@parkerbxyz parkerbxyz merged commit cda91bf into beta Aug 22, 2025
3 checks passed
@parkerbxyz parkerbxyz deleted the 134-remove-custom-proxy-functionality branch August 22, 2025 19:16
create-app-token-action-releaser bot pushed a commit that referenced this pull request Aug 22, 2025
# [3.0.0-beta.2](v3.0.0-beta.1...v3.0.0-beta.2) (2025-08-22)

### Bug Fixes

* remove custom proxy handling ([#143](#143)) ([cda91bf](cda91bf)), closes [#134](#134)
@create-app-token-action-releaser

🎉 This PR is included in version 3.0.0-beta.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@gr2m
Copy link
Contributor

gr2m commented Aug 22, 2025

Unfortunately, even with Node 24, it's not working out of the box. Now NODE_USE_ENV_PROXY needs to be set to 1 to enable the automated proxy behavior. Setting process.env.NODE_USE_ENV_PROXY='1' in the code does not work.

We see two ways to support the proxy behavior

  1. We ask users to set

       env:
         NODE_USE_ENV_PROXY: 1
  2. We spawn a subprocess in which we can set NODE_USE_ENV_PROXY=1 on startup which makes it work, but it feels quite hacky

import { spawn } from "child_process";

run();

async function run() {
  if (
    !process.env.NODE_USE_ENV_PROXY &&
    (process.env.HTTP_PROXY || process.env.HTTPS_PROXY)
  ) {
    // spawn itself with NODE_USE_ENV_PROXY=1
    const child = spawn(process.execPath, process.argv.slice(1), {
      env: { ...process.env, NODE_USE_ENV_PROXY: "1" },
      stdio: "inherit",
    });
    child.on("exit", (code) => process.exit(code));
    return;
  }

  const response = await fetch("https://example.com");
  console.log(await response.text());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove custom proxy functionality
5 participants